﻿CREATE PROCEDURE [dbo].[yaf_pollvote_check](
                @PollID   INT,
                @UserID   INT  = NULL,
                @RemoteIP NVARCHAR(10)  = NULL)
AS
    IF @UserID IS NULL
    BEGIN
        IF @RemoteIP IS NOT NULL
        BEGIN
            -- check by remote IP
            SELECT PollVoteID
            FROM   yaf_PollVote
            WHERE  PollID = @PollID
            AND RemoteIP = @RemoteIP
        END
    END
    ELSE
    BEGIN
        -- check by userid or remote IP
        SELECT PollVoteID
        FROM   yaf_PollVote
        WHERE  PollID = @PollID
        AND (UserID = @UserID
              OR RemoteIP = @RemoteIP)
    END


